<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
<<< top thin :800x174
top big: 800 x 575
left image: 380 x 580
[3:46:52 PM] Anh Ldd [Lee]: tat ca 3 versions nay co water mark o goc bottom left cua image
[3:47:06 PM] Anh Ldd [Lee]: rieng 2 cai version:
[3:47:06 PM] Anh Ldd [Lee]: [12:34 AM] Angel Garrido | Grupitec: 

<<< top big: 800 x 575
and left image: 380 x 580
no co them watermark o giua~ cai hinh
**/

define('TOP_THIN_W', 803);
define('TOP_THIN_H', 175);

define('THUMB_W',130);
define('THUMB_H',170);

define('THUMB_VW',170);
define('THUMB_VH',170);

define('THUMB_WW',300);
define('THUMB_HH',450);

define('THUMB_VWW',350);
define('THUMB_VHH',350);

define('PUBLIC_TOP_W',803);
define('PUBLIC_TOP_H',576);

define('PUBLIC_W',387);
define('PUBLIC_H',584);

define('ESCORT_THUMB_W',195);
define('ESCORT_THUMB_H',312);
// ------------------------------------------------------------------------
function explode_name($source_image)
{
	$ext = strrchr($source_image, '.');
	$name = ($ext === FALSE) ? $source_image : substr($source_image, 0, -strlen($ext));

	return array('ext' => $ext, 'name' => $name);
}

function imageGeoLanguage($image_name){
	$code = get_language_code();
	$sExtension = strtolower ( substr( $image_name, ( strrpos($image_name, '.') + 1 ) ) );
	$name = str_replace(".$sExtension",'',$image_name);
	$locationImage = $name.'_'.$code.'.'.$sExtension;
	$dir = './images/';
	$http = site_url().'/images/';
	if(!is_file($dir.$locationImage)){
		return "<img src='".$http.$image_name."' />";
	}
	return "<img src='".$http.$locationImage."' />";
}

function thumb($src, $w, $h, $is_use = true, $alt="", $title=""){
	if(!$w){
		$cond = "h=$h&zc=1";
	}elseif(!$h){
		$cond = "w=$w&zc=1";
	}else{
		$cond = "w=$w&h=$h&zc=1";
	}
	if(!$is_use){
		return "<img src='$src' alt='$alt' title='$title' />";
	}
	return "<img src='".site_url()."uploads/timthumb.php?$cond&src=$src"."' alt='$alt' title='$title' />";
}

function thumb2($src, $w, $h){
	if(!$w){
		$cond = "h=$h&zc=1";
	}elseif(!$h){
		$cond = "w=$w&zc=1";
	}else{
		$cond = "w=$w&h=$h&zc=1";
	}
	return site_url()."uploads/timthumb.php?$cond&src=$src" ;
}

function loader_image($ext=""){
	return "&nbsp;&nbsp;<img $ext src='".site_url()."media/img/ajax-loader.gif"."' />";
}

function loader_image_s($ext=""){
	return "&nbsp;&nbsp;<img $ext src='".site_url()."media/img/ajax-loader-s.gif"."' />";
}

function delete_image($ext =""){
	return "<img $ext src='".site_url()."media/img/delete.png"."' />";
}

function playvideo($file_name,$poster, $w, $h, $id=0){
	//$sExtension = strtolower ( substr( $file_name, ( strrpos($file_name, '.') + 1 ) ) );
	/** 
	return "
			<video id=\"my_video_1\" class=\"video-js vjs-default-skin\" controls
			  preload=\"auto\" width=\"$w\" height=\"$h\" poster=\"$poster\"
			  data-setup=\"{}\">
			  <source src=\"$file_name\" type='video/$sExtension'>
			</video>
		";
		**/
	if($id){
		$container = "container_{$id}";	
	}else{
		$container = "container_".uniqid();	
	}
	$site_url = site_url();
	
	if($id){
		return "<div id='$container'></div>
			<script  type= \"text/javascript\">  
				jwplayer ( \"$container\" ).setup({ 
					'id': '$container',
					'width': '$w',
					'height': '$h',
					'file': '$file_name',
					'image': '$poster',
					'allowscripaccess': 'always',
					'modes': [
						{type: 'html5'},
						{type: 'flash', src: \"$site_url/media/js/player.swf\"},
						{type: 'download'}
					],
					'skin': \"$site_url/media/skin/fs40/fs40.zip\",
					'viral':{
						allowmenu:false,
						oncomplete:false,
						onpause:false
					},
					'events':{
						onReady: function(){turnOFFdisplayButton();} ,
						onPlay: function(oldState){videoPlaying($id,oldState);},
					},
					'controlbar':'hide',
					'display':'hide'
				});  
			</script>";
	}else{
		return "<div id='$container'></div>
			<script  type= \"text/javascript\">  
				jwplayer ( \"$container\" ).setup({ 
					'id': '$container',
					'width': '$w',
					'height': '$h',
					'file': '$file_name',
					'image': '$poster',
					'allowscripaccess': 'always',
					'modes': [
						{type: 'html5'},
						{type: 'flash', src: \"$site_url/media/js/player.swf\"},
						{type: 'download'}
					],
					'skin': \"$site_url/media/skin/fs40/fs40.zip\",
					'viral':{
						allowmenu:false,
						oncomplete:false,
						onpause:false
					}
				});  
			</script>";

	}
}
 

function createImageText($string,$nameReturn){
	$directory = "./uploads/default/imagephone";
	
	if(!file_exists($directory)){
		mkdir($directory);
		chmod( $directory, 0777 ) ;
		file_put_contents($directory."/index.php","");
		file_put_contents($directory."/index.html","");
	}
	//$image_source = imagecreatefrompng($directory.'/'.'transparent.png'); 
	$image_source = imagecreatefrompng('./config/transparent.png'); 
	
	$file = $directory.'/'.$nameReturn.'.png';		
	//$black = imagecolorallocate ($image_source,39,39,36);
	$black = imagecolorallocate ($image_source,171,6,41);
	
	$font = './captcha/fonts/arial.ttf';	
	$bg_color = imagecolorat($image_source,1,1);
	//imagettftext($image_source, 10, 0, 0, 15, $black, $font, $string);
	//$font = imageloadfont('./config/automatic.gdf');
	//imagestring($image_source, $font, 0, 1, $string, $black);
	imagestring ($image_source,5,0,1,$string,$black);
	imagecolortransparent($image_source, $bg_color);
	
	imagepng ($image_source,$file);
	imagedestroy($image_source);
	return site_url().'uploads/default/imagephone/'.$nameReturn.'.png';
}


function createImageText2($string,$nameReturn){
	$directory = "./uploads/default/imagephone";
	
	if(!file_exists($directory)){
		mkdir($directory);
		chmod( $directory, 0777 ) ;
		file_put_contents($directory."/index.php","");
		file_put_contents($directory."/index.html","");
	}
	$file = $directory.'/'.$nameReturn.'.png';		
	$w = strlen($string) * 5;
	$width  = ($w <=200) ? 200:$w;
	$height = 30;	 
	$image = imagecreatetruecolor ($width,$height);
	$white = imagecolorallocate ($image,255,255,255);
	$black = imagecolorallocate ($image,0,0,0);
	imagefill($image,0,0,$white);	
	$font = './captcha/fonts/arial.ttf';	
	imagettftext($image, 12, 0, 5, 20, $black, $font, $string);
	//imagestring ($image,$font,0,0,$string,$black);	 
	imagepng ($image,$file);
	imagedestroy($image);
	return site_url().'uploads/default/imagephone/'.$nameReturn.'.png';
}
